package com.vrv.im.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.apache.log4j.Logger;

@WebFilter(urlPatterns = { "*.do" })
public class UserBindFilter implements Filter {

    final Logger logger = Logger.getLogger(getClass());

    /**
     * Default constructor.
     */
    public UserBindFilter() {
    }

    /**
     * @see Filter#destroy()
     */
    public void destroy() {
    }

    /**
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

//        String token = request.getParameter("token");
//        String openId = request.getParameter("openId");
//        if (!StringUtils.hasText(token) || !StringUtils.hasText(openId)) {
//
//            logger.error("非法参数，重定向到用户绑定页面！");
//
//            HttpServletRequest httpServletRequest = (HttpServletRequest) request;
//            String requestUrl = httpServletRequest.getRequestURI();
//            if (!requestUrl.contains("bind/goToBind")) {
//                // request.setAttribute("voModel", new UserBean());
//                // request.setAttribute("type", "error");
//                // request.setAttribute("errotMsg", "请传递参数openID，tocken");
//
//                HttpServletResponse httpServletResponse = (HttpServletResponse) response;
//                String responseUrl = httpServletRequest.getServletPath()
//                        + "/bind/goToBind.do";
//
//                logger.debug("重定向地址：" + responseUrl);
//
//                httpServletResponse.sendRedirect(responseUrl);
//            }
//        }

        // pass the request along the filter chain
        chain.doFilter(request, response);
    }

    /**
     * @see Filter#init(FilterConfig)
     */
    public void init(FilterConfig fConfig) throws ServletException {
    }

}
